<?php
namespace app\api\controller\zfcom;
class Com extends Base
{
    //获取配置
    public function getsys(){
        $d = $this->post;
        if (!isset($d['config_key'])) {
            err('请输入config_key');
        }
        $key = explode(",",$d['config_key']);
        $rs = [];
        foreach($key as $v){
            $rs[$v] = c("{$d['config_key']}");
        }
        return suc($rs);
    }

    //获取配置
    public function deploy(){
        $d = $this->post;
        if (!isset($d['uuid'])) {
            err('请输入key');
        }
        $key = explode(",",$d['uuid']);
        $rs = [];
        foreach($key as $v){
            $rs[$v] = $this->sys[$v];
        }
        return suc($rs);
    }

    public function getinfo(){
        $d = $this->post;
        $rule = [
            'token'=>'require',
        ];
        $msg = [];
        check($rule,$msg,$d);
        $userinfo = $this->db->query("select * from user where wap_token=?",[$d['token']],1);
        suc($userinfo);
    }

    //
    public function getWord(){
        $d = $this->post;
        $uuid = $d['uuid'];
        if(!empty($uuid)){
            $word = $this->db->query("select * from word where uuid = ?",[$uuid],1);
            if($word)
              $word['h5_url'] = url('h5/getword',['id'=>$word['id']]);
        }else{
            $word = $this->db->query("select * from word");
            foreach ($word as $key => $val) {
                $val['h5_url'] = url('h5/getword',['id'=>$val['id']]);
                $word[$val['uuid']] = $val;
                unset($word[$key]);
            }
        }
        suc($word);
    }
    public function getImg(){
        $d = $this->post;
        $id = $d['id'];
        $img = $this->db->query("select * from img where id = ?",[$id],1);
        suc($img);
    }
    //获取子地区名称
    public function getComAddress(){
        $d = $this->post;
        $pid = $d['pid'];
        if($pid == ''){
            $rs = $this->db->query('select id,name,parent_id from com_address');
        }else{
            $rs = $this->db->query('select id,name,parent_id from com_address where parent_id=?',[$pid]);
        }
        suc($rs);
    }
}
